<?php

namespace app\interfaces\model;

use think\Db;
use think\Model;
use think\Request;

class MerchantOrder extends Model
{

    // 设置主表名
    protected $table = 'sun_member_order';

    // 时间
    protected function getCreateTimeAttr($value, $data)
    {
        return date('Y-m-d H:i:s', $data['create_time']);
    }

    // 退货类型
    protected function getRefundTypeAttr($value, $data)
    {
        return (int)Db::name('member_refund')->where(['order_number' => $data['shop_order_number']])->value('type');
    }

    // 退货状态
    protected function getRefundStatusAttr($value, $data)
    {
        return (int)Db::name('member_refund')->where(['order_number' => $data['shop_order_number']])->value('status');
    }


    public function goods()
    {

        $title = Request::instance()->param('title');

        $condition['id'] = ['gt', 0];

        if (!empty($title)) $condition['title'] = ['like', '%' . $title . '%'];

        return $this->hasMany('MemberOrderAttached', 'order_id', 'id')
            ->where($condition)
            ->field('goods_id,attr,number,price,title,thumb_img');
    }

}
